home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / pctjag86.arc / ATFLOAT.C < prev    next >
Text File  |  1986-05-29  |  2KB  |  82 lines

  1. /*
  2.  * ATFLOAT -- PC Tech Journal Floating-Point Performance Test
  3.  *
  4.  * Version 1.00
  5.  * Last modified 05/23/86
  6.  * Copyright (c) 1986, PC Tech Journal
  7.  * Program by: Paul Pierce, Ted Forgeron, Steven Armbrust
  8.  *
  9.  * Measures the time it takes to multiply two matrices of
  10.  * double-precision floating-point numbers and compares it
  11.  * to the time it takes an 8MHz PC/AT with an 80287 math
  12.  * coprocessor to do the same.
  13.  */
  14.  
  15. /* Number of iterations the test runs for. */
  16. #define TRIALS 100
  17.  
  18. /* Dimension of the matrix */
  19. #define SIZE 20
  20.  
  21. unsigned long time();
  22. unsigned rand();
  23.  
  24. double drand()
  25. {
  26.  
  27.         return (double)rand() / 32767;
  28. }
  29.  
  30. double a[SIZE][SIZE];
  31. double b[SIZE][SIZE];
  32.  
  33. main()
  34. {
  35.         int i;
  36.         register j, k;
  37.         int n;
  38.         unsigned long start;
  39.         unsigned long total;
  40.         unsigned trials;
  41.         double t;
  42.  
  43.         trials = TRIALS;
  44.  
  45.         /*
  46.          * Fill matrix with random numbers.
  47.          */
  48.  
  49.         for (i = 0; i < SIZE; i++)
  50.                 for (j = 0; j < SIZE; j++)
  51.                         a[i][j] = drand();
  52.  
  53.         /*
  54.          * Repeatedly multiply the matrices and
  55.          * report the relative and absolute times.
  56.          */
  57.  
  58.         start = time();
  59.         printf("\nATFLOAT -- PC Tech Journal AT Floating-Point");
  60.         printf(" Performance Test\n");
  61.         printf("Version 1.00, Copyright (c) 1986 PC Tech ");
  62.         printf("Journal\n");
  63.         printf("\nThis test runs for %d iterations ...\n", trials);
  64.         for (n = 1; n <= trials; n++) {
  65.                 printf("%d\r", n);
  66.                 for (i = 0; i < SIZE; i++) {
  67.                         for (j = 0; j < SIZE; j++) {
  68.                                 t = 0;
  69.                                 for (k = 0; k < SIZE; k++)
  70.                                         t += a[k][j] * a[i][k];
  71.                                 b[i][j] = t;
  72.                         }
  73.                 }
  74.         }
  75.         total = time() - start;
  76.         printf("\rElapsed time is %ld seconds.\n\n", total, trials);
  77.         printf("Floating-point performance index relative\n");
  78.         printf("to 8MHz IBM PC/AT with 80287 = %2.1f\n",
  79.                 94.0 / (float) total);
  80.  
  81. }
  82.